<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        #shop-car li {
            border: 1px dotted red;
            margin: 20px 0;
            padding: 20px;
        }

        .container {
            width: 400px;
            padding: 20px;
        }
    </style>

    <div class="container">
        <!-- <ul id="shop-car">
            <li>
                <input type="checkbox"  checked/>
                <div>商品名称:</div>
                <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg"
                    alt="">
                <div>商品价格:50</div>
                <div>购买数量:30</div>
                <div>商品规格: 黑</div>
                <div>是否选中:选中吧OR不选中</div>
            </li>
        </ul>
        <p id="totalnum">总数量:xxx</p> -->
    </div>

    <script src="./apply.js"></script>
    <script>
        let container = document.querySelector('.container');
        console.log(container);

        // 渲染
        let str='';
        cartGoods.forEach((item,index)=> {
            str+=`<div class="container">\
        <ul id="shop-car">\
            <li>\
                <input type="checkbox"  checked/>\
                <div>商品名称:${item.goodsname}</div>\
                <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg"\
                    alt="">\
                <div>商品价格:${item.price}</div>\
                <div>购买数量:30</div>\
                <div>商品规格: 黑</div>\
                <div>是否选中:${item.isChecked?item.isChecked:!item.isChecked}</div>\
            </li>\
        </ul>\
        <p id="totalnum">总数量:xxx</p>\
    </div>`
        });
        container.innerHTML=str;

        let inp=document.getElementsByTagName('input');
        console.log(inp);
        Array.from(inp).forEach(function(item,index){
            console.log(item.parentNode.lastElementChild.innerHTML.split(':')[1]);
            item.onclick=function(){
              if(item.checked==true){
                  console.log('已选中');
                  item.parentNode.lastElementChild.innerHTML='是否选中:true'
              }else{
                  console.log('未选中');
                  item.parentNode.lastElementChild.innerHTML='是否选中:false'
              }
            }
        })   
        
    </script>
</body>
</html>